<?php
class Admin_Model_Department extends Application_Model_Db_Db
{
    public function getAvailableForRoleDepartments($roleId) {
        $sql = "SELECT
                    `role_department`.`department_id` AS `id`,
                    IFNULL(`department`.`name`, 'Без кафедры') AS `name`
                FROM `role`
                INNER JOIN `role_department`
                    ON `role`.`id` = `role_department`.`role_id`
                LEFT JOIN `department`
                    ON `role_department`.`department_id` = `department`.`id`
                WHERE `role`.`id` = ?";
        return $this->_db->fetchAll($sql, $roleId);
    }

    public function getAllDepartments() {
        $sql = "SELECT
                    `id`,
                    `name`
                FROM `department`";
        return $this->_db->fetchAll($sql);
    }

    public function getAllDepartmentsExcept($departments) {
        $where = '';
        if ($departments) {
            $where = " WHERE `id` NOT IN ($departments)";
        }
        $sql = "SELECT
                    `id`,
                    `name`
                FROM `department`
                {$where}";      
        return $this->_db->fetchAll($sql);
    }
}